<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #div1 {
            width: 100px;
            padding: 10px;
            border: 1px solid #ccc;
            margin: 10px;
        }



        /* #div1 {
            width: 200px;
            height: 200px;
            border: 2px solid red;
            padding: 5px;
            margin: 1px;
            background: green;
        } */
    </style>
</head>

<body>
    <div id="div1"></div>
    <!-- 宽度应该是122 -->
    <script>
        var div = document.querySelector('#div1')
        console.log(div.offsetWidth);
    // width+padding*2+border*2不加margin
    </script>
</body>

</html>